package com.sentinel.demo.pull.file.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sentinel.demo.common.SpringBeanUtils;
import com.sentinel.demo.common.Swagger2Config;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Pull模式
 * @author dsy on 2019/12/7
 */
@Slf4j
@Controller
public class PullModeController {

    @ResponseBody
    @SentinelResource(value = "listBrand",blockHandler = "deaultBlockHandle")
    @ApiOperation(value = "拉模式-文件测试")
    @RequestMapping(value = "/listBrand", method = RequestMethod.GET)
    public String listBrand(String id){
        log.info("id = {}",id);
        return "OK，id="+id;
    }

    public static String deaultBlockHandle(String id ,BlockException be){
        System.out.println("限流异常："+be.getRule()+ ",e." + be.getMessage());
        return "限流异常：" + be.getRule();
    }
}
